@@ -1,5 +1,13 @@
Changes for MooseX-Role-Parameterized
+0.22 November 26, 2010
+ * The test suite now uses Test::Fatal instead of Test::Exception (Karen
+ Etheridge).
+ * Fix Test::More dependency (reported by Father Chrysostomos)
+
+0.21 November 15, 2010
+ * "package" arg can now tell generate_role to use a specific package (rjbs)
+
0.20 November 2, 2010
* Minor test refactoring to fix blead support [rt.perl.org #78244]
@@ -4,9 +4,9 @@ author:
- 'Shawn M Moore, C<sartak@gmail.com>'
build_requires:
ExtUtils::MakeMaker: 6.42
- Test::Exception: 0.27
+ Test::Fatal: 0
Test::Moose: 0
- Test::More: 0.88
+ Test::More: 0.96
configure_requires:
ExtUtils::MakeMaker: 6.42
distribution_type: module
@@ -27,4 +27,4 @@ resources:
homepage: http://github.com/sartak/MooseX-Role-Parameterized/tree
license: http://dev.perl.org/licenses/
repository: git://github.com/sartak/MooseX-Role-Parameterized.git
-version: 0.20
+version: 0.22
@@ -1,5 +1,6 @@
# Load the Module::Install bundled in ./inc/
use inc::Module::Install;
+use Module::Install::GithubMeta;
# Define metadata
name 'MooseX-Role-Parameterized';
@@ -8,8 +9,8 @@ githubmeta;
requires 'Moose' => '0.78';
test_requires 'Test::Moose';
-test_requires 'Test::More' => '0.88';
-test_requires 'Test::Exception' => '0.27';
+test_requires 'Test::More' => '0.96';
+test_requires 'Test::Fatal';
WriteAll;
@@ -2,7 +2,7 @@ package MooseX::Role::Parameterized::Meta::Parameter;
use Moose;
extends 'Moose::Meta::Attribute';
-our $VERSION = '0.19';
+our $VERSION = '0.22';
# This doesn't actually do anything because _process_options does not consult
# the default value of "is". hrm.
@@ -2,7 +2,7 @@ package MooseX::Role::Parameterized::Meta::Role::Parameterizable;
use Moose;
extends 'Moose::Meta::Role';
-our $VERSION = '0.19';
+our $VERSION = '0.22';
use MooseX::Role::Parameterized::Meta::Role::Parameterized;
use MooseX::Role::Parameterized::Meta::Parameter;
@@ -82,10 +82,19 @@ sub generate_role {
my $parameterized_role_metaclass = $self->parameterized_role_metaclass;
Class::MOP::load_class($parameterized_role_metaclass);
- my $role = $parameterized_role_metaclass->create_anon_role(
- genitor => $self,
- parameters => $parameters,
- );
+ my $role;
+ if ($args{package}) {
+ $role = $parameterized_role_metaclass->create(
+ $args{package},
+ genitor => $self,
+ parameters => $parameters,
+ );
+ } else {
+ $role = $parameterized_role_metaclass->create_anon_role(
+ genitor => $self,
+ parameters => $parameters,
+ );
+ }
local $MooseX::Role::Parameterized::CURRENT_METACLASS = $role;
@@ -187,7 +196,8 @@ The arguments are those specified by the consumer as parameter values.
Returns a new instance of
L<MooseX::Role::Parameterized::Meta::Role::Parameterized> based on the
arguments. The arguments are a hash reference of C<parameters> and, if
-available, a C<consumer> metaobject.
+available, a C<consumer> metaobject. A C<package> argument may be given to use
+a specific package name instead of autogenerating one.
=head2 apply
@@ -3,7 +3,7 @@ use Moose;
extends 'Moose::Meta::Role';
with 'MooseX::Role::Parameterized::Meta::Trait::Parameterized';
-our $VERSION = '0.19';
+our $VERSION = '0.22';
__PACKAGE__->meta->make_immutable;
no Moose;
@@ -1,7 +1,7 @@
package MooseX::Role::Parameterized::Meta::Trait::Parameterized;
use Moose::Role;
-our $VERSION = '0.19';
+our $VERSION = '0.22';
use MooseX::Role::Parameterized::Parameters;
@@ -1,7 +1,7 @@
package MooseX::Role::Parameterized::Parameters;
use Moose;
-our $VERSION = '0.19';
+our $VERSION = '0.22';
__PACKAGE__->meta->make_immutable;
no Moose;
@@ -7,7 +7,7 @@ use Scalar::Util 'blessed';
use MooseX::Role::Parameterized::Meta::Role::Parameterizable;
-our $VERSION = '0.20';
+our $VERSION = '0.22';
our $CURRENT_METACLASS;
Moose::Exporter->setup_import_methods(
@@ -2,7 +2,7 @@
use strict;
use warnings;
use Test::More tests => 16;
-use Test::Exception;
+use Test::Fatal;
use MooseX::Role::Parameterized::Parameters;
@@ -38,9 +38,9 @@ ok($parameter->is_required, "parameter is required");
ok(MyRole::LengthParameter->meta->has_parameter('length'), 'has_parameter');
ok(!MyRole::LengthParameter->meta->has_parameter('kjhef'), 'has_parameter');
-throws_ok {
+like( exception {
MyRole::LengthParameter->meta->construct_parameters;
-} qr/^Attribute \(length\) is required/;
+}, qr/^Attribute \(length\) is required/);
$p = MyRole::LengthParameter->meta->construct_parameters(
length => 5,
@@ -48,9 +48,9 @@ $p = MyRole::LengthParameter->meta->construct_parameters(
is($p->length, 5, "correct length");
-throws_ok {
+like( exception {
$p->length(10);
-} qr/^Cannot assign a value to a read-only accessor/;
+}, qr/^Cannot assign a value to a read-only accessor/);
do {
package MyRole::LengthParameter;
@@ -1,8 +1,7 @@
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 8;
-use Test::Exception;
+use Test::More tests => 3;
my ($parameters, %args);
@@ -32,22 +31,54 @@ do {
ok(MyPerson->meta->has_role_generator, "MyPerson has a role generator");
-my $role = MyPerson->meta->generate_role(
- parameters => {
- default_age => 7,
- },
-);
+subtest "generation of an anonymous role" => sub {
+ plan tests => 8;
+ my $role = MyPerson->meta->generate_role(
+ parameters => {
+ default_age => 7,
+ },
+ );
+
+ isa_ok($role, 'Moose::Meta::Role', 'generate_role created a role');
-isa_ok($role, 'Moose::Meta::Role', 'generate_role created a role');
+ like($role->name, qr{ANON}, '...with an anonymous name');
-is($role->parameters, $parameters, 'the generated role knows its parameters');
+ is($role->parameters, $parameters, 'the generated role knows its parameters');
-is($parameters->default_age, 7);
-is($args{operating_on}, $role, "we pass in the role metaclass that we're operating on");
+ is($parameters->default_age, 7);
+ is($args{operating_on}, $role, "we pass in the role metaclass that we're operating on");
-my $age_attr = $role->get_attribute('age');
-is($age_attr->{default}, 7, "role's age attribute has the right default");
+ my $age_attr = $role->get_attribute('age');
+ is($age_attr->{default}, 7, "role's age attribute has the right default");
+
+ my $birthday_method = $role->get_method('birthday');
+ is($birthday_method->name, 'birthday', "method name");
+ is($birthday_method->package_name, $role->name, "package name");
+};
+
+subtest "generating a role with a provided name" => sub {
+ plan tests => 8;
+
+ my $role = MyPerson->meta->generate_role(
+ package => 'RJBS::Was::Here',
+ parameters => {
+ default_age => 10,
+ },
+ );
-my $birthday_method = $role->get_method('birthday');
-is($birthday_method->name, 'birthday', "method name");
-is($birthday_method->package_name, $role->name, "package name");
+ isa_ok($role, 'Moose::Meta::Role', 'generate_role created a role');
+
+ is($role->name, 'RJBS::Was::Here', '...with the name we expected');
+
+ is($role->parameters, $parameters, 'the generated role knows its parameters');
+
+ is($parameters->default_age, 10);
+ is($args{operating_on}, $role, "we pass in the role metaclass that we're operating on");
+
+ my $age_attr = $role->get_attribute('age');
+ is($age_attr->{default}, 10, "role's age attribute has the right default");
+
+ my $birthday_method = $role->get_method('birthday');
+ is($birthday_method->name, 'birthday', "method name");
+ is($birthday_method->package_name, $role->name, "package name");
+};
@@ -2,7 +2,7 @@
use strict;
use warnings;
use Test::More tests => 22;
-use Test::Exception;
+use Test::Fatal;
my %args;
do {
@@ -122,21 +122,21 @@ do {
can_ok('MyClass::Three' => qw(freeze_Dumper freeze_Storable thaw_Dumper thaw_Storable store dump));
is($args{consumer}, MyClass::Three->meta, 'Role block receives consumer');
-throws_ok {
+like( exception {
package MyClass::Error::Required;
use Moose;
with 'MyRole::Storage';
-} qr/^Attribute \(format\) is required/;
+}, qr/^Attribute \(format\) is required/);
-throws_ok {
+like( exception {
package MyClass::Error::Invalid;
use Moose;
with 'MyRole::Storage' => {
format => 'YAML',
};
-} qr/^Attribute \(format\) does not pass the type constraint/;
+}, qr/^Attribute \(format\) does not pass the type constraint/);
-throws_ok {
+like( exception {
package MyRole::Sans::Block;
use MooseX::Role::Parameterized;
@@ -145,7 +145,7 @@ throws_ok {
package MyClass::Error::BlocklessRole;
use Moose;
with 'MyRole::Sans::Block' => {};
-} qr/^\QA role generator is required to apply parameterized roles (did you forget the 'role { ... }' block in your parameterized role 'MyRole::Sans::Block'?)\E/;
+}, qr/^\QA role generator is required to apply parameterized roles (did you forget the 'role { ... }' block in your parameterized role 'MyRole::Sans::Block'?)\E/);
sub cant_ok {
local $Test::Builder::Level = $Test::Builder::Level + 1;
@@ -2,7 +2,7 @@
use strict;
use warnings;
use Test::More tests => 5;
-use Test::Exception;
+use Test::Fatal;
do {
package MyRole::Requires;
@@ -32,40 +32,40 @@ sub requires_names {
} @_
}
-throws_ok {
+like( exception {
Moose::Meta::Class->create_anon_class(
roles => [ requires_names('alpha') ],
);
-} qr/'Moose::Meta::Role::__ANON__::SERIAL::\d+' requires the method 'alpha' to be implemented by 'Class::MOP::Class::__ANON__::SERIAL::\d+'/;
+}, qr/'Moose::Meta::Role::__ANON__::SERIAL::\d+' requires the method 'alpha' to be implemented by 'Class::MOP::Class::__ANON__::SERIAL::\d+'/);
-lives_ok {
+is (exception {
Moose::Meta::Class->create_anon_class(
methods => {
alpha => sub {},
},
roles => [ requires_names('alpha') ],
);
-};
+}, undef);
-throws_ok {
+like( exception {
Moose::Meta::Class->create_anon_class(
methods => {
alpha => sub {},
},
roles => [ requires_names('alpha', 'beta') ],
);
-} qr/'Moose::Meta::Role::__ANON__::SERIAL::\d+\|Moose::Meta::Role::__ANON__::SERIAL::\d+' requires the method 'beta' to be implemented by 'Class::MOP::Class::__ANON__::SERIAL::\d+'/;
+}, qr/'Moose::Meta::Role::__ANON__::SERIAL::\d+\|Moose::Meta::Role::__ANON__::SERIAL::\d+' requires the method 'beta' to be implemented by 'Class::MOP::Class::__ANON__::SERIAL::\d+'/);
-throws_ok {
+like( exception {
Moose::Meta::Class->create_anon_class(
methods => {
beta => sub {},
},
roles => [ requires_names('alpha', 'beta') ],
);
-} qr/'Moose::Meta::Role::__ANON__::SERIAL::\d+\|Moose::Meta::Role::__ANON__::SERIAL::\d+' requires the method 'alpha' to be implemented by 'Class::MOP::Class::__ANON__::SERIAL::\d+'/;
+}, qr/'Moose::Meta::Role::__ANON__::SERIAL::\d+\|Moose::Meta::Role::__ANON__::SERIAL::\d+' requires the method 'alpha' to be implemented by 'Class::MOP::Class::__ANON__::SERIAL::\d+'/);
-lives_ok {
+is (exception {
Moose::Meta::Class->create_anon_class(
methods => {
alpha => sub {},
@@ -73,5 +73,5 @@ lives_ok {
},
roles => [ requires_names('alpha', 'beta') ],
);
-};
+}, undef);
@@ -2,7 +2,7 @@
use strict;
use warnings;
use Test::More tests => 3;
-use Test::Exception;
+use Test::Fatal;
do {
package MyRole::Excluder;
@@ -35,21 +35,21 @@ sub excludes_roles {
} @_
}
-lives_ok {
+is (exception {
Moose::Meta::Class->create_anon_class(
roles => [ excludes_roles('Role::A') ],
);
-};
+}, undef);
-throws_ok {
+like( exception {
Moose::Meta::Class->create_anon_class(
roles => [ 'Role::A', excludes_roles('Role::A') ],
);
-} qr/^Conflict detected: Role Moose::Meta::Role::__ANON__::SERIAL::\d+ excludes role 'Role::A'/;
+}, qr/^Conflict detected: Role Moose::Meta::Role::__ANON__::SERIAL::\d+ excludes role 'Role::A'/);
-lives_ok {
+is (exception {
Moose::Meta::Class->create_anon_class(
roles => [ 'Role::B', excludes_roles('Role::A') ],
);
-};
+}, undef);
@@ -2,30 +2,29 @@
use strict;
use warnings;
use Test::More tests => 5;
-
-use Test::Exception;
+use Test::Fatal;
do {
package MyRole::Storage;
use MooseX::Role::Parameterized;
- ::throws_ok {
+ ::like( ::exception {
parameter()
- } qr/^You must provide a name for the parameter/;
+ }, qr/^You must provide a name for the parameter/);
role {
- ::throws_ok {
+ ::like( ::exception {
extends 'MyRole::Parameterized';
- } qr/^Roles do not currently support 'extends'/;
- ::throws_ok {
+ }, qr/^Roles do not currently support 'extends'/);
+ ::like( ::exception {
inner()
- } qr/^Roles cannot support 'inner'/;
- ::throws_ok {
+ }, qr/^Roles cannot support 'inner'/);
+ ::like( ::exception {
augment()
- } qr/^Roles cannot support 'augment'/;
- ::throws_ok {
+ }, qr/^Roles cannot support 'augment'/);
+ ::like( ::exception {
parameter()
- } qr/^'parameter' may not be used inside of the role block/;
+ }, qr/^'parameter' may not be used inside of the role block/);
};
};
@@ -2,35 +2,35 @@
use strict;
use warnings;
use Test::More tests => 4;
-use Test::Exception;
+use Test::Fatal;
do {
package MyRole;
use MooseX::Role::Parameterized;
- ::throws_ok {
+ ::like( ::exception {
parameter 'alias';
- } qr/^The parameter name \(alias\) is currently forbidden/;
+ }, qr/^The parameter name \(alias\) is currently forbidden/);
- ::throws_ok {
+ ::like( ::exception {
parameter 'excludes';
- } qr/^The parameter name \(excludes\) is currently forbidden/;
+ }, qr/^The parameter name \(excludes\) is currently forbidden/);
};
do {
package MyClass;
use MooseX::Role::Parameterized;
- ::throws_ok {
+ ::like( ::exception {
with MyRole => {
alias => 1,
};
- } qr/^The parameter name \(alias\) is currently forbidden/;
+ }, qr/^The parameter name \(alias\) is currently forbidden/);
- ::throws_ok {
+ ::like( ::exception {
with MyRole => {
excludes => 1,
};
- } qr/^The parameter name \(excludes\) is currently forbidden/;
+ }, qr/^The parameter name \(excludes\) is currently forbidden/);
};
@@ -1,7 +1,7 @@
use strict;
use warnings;
use Test::More;
-use Test::Exception;
+use Test::Fatal;
use FindBin;
use lib "$FindBin::Bin/lib";
@@ -24,17 +24,17 @@ use lib "$FindBin::Bin/lib";
{
package Moo;
use Moose;
- ::lives_ok(sub {
+ ::is( ::exception {
with 'Foo';
- });
+ }, undef);
}
{
package se;
use Moose;
- ::lives_ok(sub {
+ ::is( ::exception {
with 'Bar';
- });
+ }, undef);
}
my $foo = Moo->meta->roles->[0];
@@ -3,7 +3,6 @@ use strict;
use warnings;
use Test::More tests => 7;
-use Test::Exception;
do {
package MyCompositeRoleA;